{$CLEO .cs}
0000:
 

model.Load(#STREAK)
model.Load(#STREAKC)
load_requested_models

const
    train_stopped = 10@ 

end 
train_stopped=0 
:1
wait 0
if and 
model.Available(#STREAK)
model.Available(#STREAKC)
jf @1 
//0208: 17@ = random_float_in_ranges -100.2 100.2
0209: 17@ = random_int_in_ranges 0 7

actor.StorePos( player1, 22@,23@,24@)
04C4: store_coords_to 22@ 23@ 24@ from_actor player1 with_offset  100.0   100.0 0.0
if 17@ == 0 
then
04C4: store_coords_to 22@ 23@ 24@ from_actor player1 with_offset -100.0  -100.0 0.0
end
if 17@ == 1 
then
04C4: store_coords_to 22@ 23@ 24@ from_actor player1 with_offset  100.0 100.0 0.0
end
if 17@ == 2
then
04C4: store_coords_to 22@ 23@ 24@ from_actor player1 with_offset  100.0 -100.0 0.0
end
if 17@ == 3
then
04C4: store_coords_to 22@ 23@ 24@ from_actor player1 with_offset  -100.0  100.0 0.0
end
if 17@ == 4
then
04C4: store_coords_to 22@ 23@ 24@ from_actor player1 with_offset   100.0  0.0 0.0
end
if 17@ == 5
then
04C4: store_coords_to 22@ 23@ 24@ from_actor player1 with_offset  100.0  0.0 0.0
end
if 17@ == 6
then
04C4: store_coords_to 22@ 23@ 24@ from_actor player1 with_offset  -100.0  0.0 0.0
end
06D8: 0@ = create_train_at  22@ 23@ 24@ type 16 direction 1
06DC: set_train 0@ acc 60.0
06DD: set_train 0@ speed 60.0
 1@ = marker.CreateAboveCar(0@)
 marker.SetColor(1@, 4)
 marker.SetIconSize(1@,2)
018B: set_marker 1@ radar_mode 0
     wait 500
    while   is_car_defined 0@  
    wait 0
        if is_car_defined 0@ 
        then 
                if train_stopped==0
                then
                    if or 
                     01AF:   car 0@ sphere 0 in_sphere  -456.6826 -4437.9531 4.9662 radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere -3945.3315 -6119.2861 16.8353  radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere -3082.8687 -4006.6772 24.3862  radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere -3063.6467 -3997.9824 24.3862  radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere -3416.6235 -2364.6602 24.3862  radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere -3445.5122 -2396.7639 24.3862  radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere  -4446.6768 -1600.9254 24.3928 radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere  -3399.9766 -2382.0942 25.3298 radius 6.3 6.3 5.0
                    

                    then
                        train_stopped=1
                        gosub @slow_stop_train 
                    end
                    if or 
                     01AF:   car 0@ sphere 0 in_sphere   -454.9391 -3148.9839 4.4562 radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere  -1782.2487 -4751.8213 24.3862 radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere -1268.0254 -5437.541 25.3298 radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere  -470.0653 -3148.7375 4.4562 radius 6.3 6.3 3.0
     

                     01AF:   car 0@ sphere 0 in_sphere  4640.2954 -3396.4387 21.5684 radius 6.3 6.3 3.0
                     01AF:   car 0@ sphere 0 in_sphere 4431.5571 -1693.0486 3.4384  radius 3.0 3.0 3.0
                     
                      01AF:   car 0@ sphere 0 in_sphere  -765.1942 -3739.9788 24.3862 radius 8.3 8.3 3.0 
                      01AF:   car 0@ sphere 0 in_sphere  -3079.4595 -5623.647 11.2062 radius 8.3 8.3 3.0 
     
                    then
                        train_stopped=1
                        gosub @stop_train 
                    end
                    if     
                     01AF:   car 0@ sphere 0 in_sphere -3423.877 -2418.0564 24.3862 radius 6.3 6.3 3.0 
                    

                    then
                        train_stopped=1
                        gosub @slow_stop_train 
                    end
               end     
               {
                 or
                  01AF:   car 0@ sphere 0 in_sphere  -1710.9052 -4754.1011 24.3862 radius 2.3 2.3 3.0
                  01AF:   car 0@ sphere 0 in_sphere -393.6799 -3154.7014 4.4562  radius 2.3 2.3 3.0
                  01AF:   car 0@ sphere 0 in_sphere -458.9049 -4494.7681 4.9662  radius 2.3 2.3 3.0
                  01AF:   car 0@ sphere 0 in_sphere  -1282.1602 -5435.0381 24.3862 radius 2.3 2.3 3.0


                  01AF:   car 0@ sphere 0 in_sphere  -1240.9048 -5439.3286 24.3862 radius 2.3 2.3 3.0
                  01AF:   car 0@ sphere 0 in_sphere   radius 2.3 2.3 3.0
                  01AF:   car 0@ sphere 0 in_sphere   radius 2.3 2.3 3.0
                  01AF:   car 0@ sphere 0 in_sphere   radius 2.3 2.3 3.0

                                                                                   }
                 if and
                 train_stopped==1
                  32@ >= 10000
                 then
                    train_stopped=0
                    wait 200
                    if  is_car_defined 0@
                    jf @error 
                    06DC: set_train 0@ acc 10.0
                    06DD: set_train 0@ speed 10.0
                    wait 200
                    if  is_car_defined 0@
                    jf @error 
                    06DC: set_train 0@ acc 20.0
                    06DD: set_train 0@ speed 20.0
                    wait 200
                    if  is_car_defined 0@
                    jf @error 
                    06DC: set_train 0@ acc 30.0
                    06DD: set_train 0@ speed 30.0
                    wait 200
                    if  is_car_defined 0@
                    jf @error 
                    06DC: set_train 0@ acc 40.0
                    06DD: set_train 0@ speed 40.0
                    wait 200
                    if  is_car_defined 0@
                    jf @error 
                    06DC: set_train 0@ acc 50.0
                    06DD: set_train 0@ speed 50.0
                    wait 200
                    if  is_car_defined 0@
                    jf @error 
                    06DC: set_train 0@ acc 60.0
                    06DD: set_train 0@ speed 60.0
                    32@ = 0 
                    
                 end  
        end
        
        if 8205:   not actor $PLAYER_ACTOR near_car 0@ radius 170.0 170.0 170.0 flag 0

        then
            //   show_text_box "Train will now disappear..."
            model.Destroy(#STREAK)
            model.Destroy(#STREAKC)
        
           if is_car_defined 0@
           then
                    06DC: set_train 0@ acc 60.0
                    06DD: set_train 0@ speed 60.0
            
              07BE: remove_references_to_train 0@

           end
           terminate_this_custom_script
        end 
    end
    
    :error 
    model.Destroy(#STREAK)
    model.Destroy(#STREAKC)

   if is_car_defined 0@
   then
                    06DC: set_train 0@ acc 60.0
                    06DD: set_train 0@ speed 60.0
    
      07BE: remove_references_to_train 0@

   end    
terminate_this_custom_script 

:stop_train
    wait 200
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 50.0
    06DD: set_train 0@ speed 40.0
    wait 200
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 40.0
    06DD: set_train 0@ speed 40.0
    
    wait 200
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 30.0
    06DD: set_train 0@ speed 30.0
    wait 200
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 20.0
    06DD: set_train 0@ speed 20.0
    wait 200
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 10.0
    06DD: set_train 0@ speed 10.0
    wait 200
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 0.0
    06DD: set_train 0@ speed 0.0
    32@=0 
 
return  
:slow_stop_train
    wait 500
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 50.0
    06DD: set_train 0@ speed 40.0
    wait 500
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 40.0
    06DD: set_train 0@ speed 40.0
    
    wait 500
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 30.0
    06DD: set_train 0@ speed 30.0
    wait 500
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 20.0
    06DD: set_train 0@ speed 20.0
    wait 500
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 10.0
    06DD: set_train 0@ speed 10.0
    wait 500
    if  is_car_defined 0@
    return_if_false
    06DC: set_train 0@ acc 0.0
    06DD: set_train 0@ speed 0.0
    32@=0 
    
return  
 